﻿
using System;

namespace HK.Core.Counter.Protocol
{
    /// <summary>
    /// 计数器状态.
    /// </summary>
    public enum CounterState {
        /// <summary>
        /// 无.
        /// </summary>
        None,
        /// <summary>
        /// 闲置.
        /// </summary>
        Idle,
        /// <summary>
        /// 计数中.
        /// </summary>
        Counting,
        /// <summary>
        /// 结束计数.
        /// </summary>
        End
    }

    /// <summary>
    /// 计数器类型.
    /// </summary>
    public enum CounterType {
        /// <summary>
        /// 时间计数器.
        /// </summary>
        TimeCounter,
        /// <summary>
        /// 数字计数器.
        /// </summary>
        NumberCounter,
        /// <summary>
        /// 进度计数器
        /// </summary>
        ProgressCount
    }

    /// <summary>
    /// 计数器模式.
    /// </summary>
    public enum CounterMode {
        /// <summary>
        /// 倒计时.
        /// </summary>
        CountDown,
        /// <summary>
        /// 顺计时.
        /// </summary>
        CountUp
    }
    
    /// <summary>
    /// 接口 : 计数器
    /// </summary>
    public interface ICounter : IDisposable
    {
        /// <summary>
        /// 类型.
        /// </summary>
        CounterType Type { get; }

        /// <summary>
        /// 模式.
        /// </summary>
        CounterMode Mode { get; }
        
        /// <summary>
        /// 模式.
        /// </summary>
        CounterState State { get; }
        
        /// <summary>
        /// 更新时间间隔<BR/>
        /// (单位:100毫微秒)
        /// </summary>
        long Interval { get; }
        
        /// <summary>
        /// 变化时间(单位:100毫微秒)
        /// </summary>
        long DeltaTime { get; }

#region Status

        /// <summary>
        /// 空闲标志位.
        /// </summary>
        bool IsIdle { get; }

        /// <summary>
        /// 计数标志位
        /// </summary>
        bool IsCounting { get; }

        /// <summary>
        /// 循环计数标志位.
        /// </summary>
        bool Loop { get; }
        
        /// <summary>
        /// 暂停标志位
        /// </summary>
        bool Pausing { get; }

#endregion

#region Action

        /// <summary>
        /// 开始计数器.
        /// </summary>
        void Start ();

        /// <summary>
        /// 暂停计数器.
        /// </summary>
        void Pause();

        /// <summary>
        /// 回复/继续
        /// </summary>
        void Resume();

        /// <summary>
        /// 结束计数器.
        /// </summary>
        void End ();

        /// <summary>
        /// 重置计数器.
        /// </summary>
        void Reset ();

        /// <summary>
        /// 重启计数器.
        /// </summary>
        void Restart ();

#endregion

    }

    /// <summary>
    /// 接口 : 计数器
    /// </summary>
    /// <typeparam name="TType">值类型</typeparam>
    public interface ICounter<TType> : ICounter
    {
        /// <summary>
        /// 目标值.
        /// </summary>
        TType DstValue { get; }
        
        /// <summary>
        /// 当前值.
        /// </summary>
        TType Value { get; }

        /// <summary>
        /// 重置最大值
        /// </summary>
        /// <param name="iValue">值</param>
        void ResetMaxValue(TType iValue);
        
        /// <summary>
        /// 更新计数器.
        /// </summary>
        /// <param name="iDeltaValue">变化值.</param>
        /// <returns><c>true</c>, 已经溢出, <c>false</c> 尚未溢出.</returns>
        bool Update (TType iDeltaValue);

        /// <summary>
        /// 取得计数器值（根据类型不同，格式也不同）.
        /// </summary>
        /// <returns>当前值(字符串)</returns>
        string GetValue ();
    }
    
    /// <summary>
    /// 接口 : 时间计数器
    /// </summary>
    public interface ITimeCounter : ICounter<float> {}
}
